import { fileURLToPath, URL } from 'url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import  { VantResolve, createStyleImportPlugin, } from 'vite-plugin-style-import';
import Components from 'unplugin-vue-components/vite';
// 自动压缩dist包
import type { CompressOptions } from 'rollup-plugin-compress-dist';
import compressDist from 'rollup-plugin-compress-dist';
import { flattenArrayable } from '_@antfu_utils@0.5.2@@antfu/utils';
const compressOpts: CompressOptions<'zip'> = {
    type: 'zip',
    archiverName: 'dist.zip',
    sourceName: 'dist',
};
// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        vueJsx(),
        compressDist(compressOpts),
        createStyleImportPlugin({
            resolves: [ ],
            libs: [
              // If you don’t have the resolve you need, you can write it directly in the lib, or you can provide us with PR
              {
                libraryName: "vant",
                // esModule: fla,
                resolveStyle: (name) => {
                  return `vant/es/${name}/style/index`;
                }
              },
            ],
          }),
          Components({
            resolvers: [
                // AntDesignVueResolver()
            ],
          }),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    css: {
        // css预处理器
        preprocessorOptions: {
          // 引入 var.scss 这样就可以在全局中使用 var.scss中预定义的变量了
          // 给导入的路径最后加上 ;
          less: {
            // additionalData: '@import "@/assets/styles/global.less";',
            modifyVars: {
              // 'primary-color': '#1899ff',
            },
            javascriptEnabled: true,
          },
        },
      },
})
